<?php
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/model/interfaces/IPurchaseOrderAccessDao.php';
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/model/interfaces/IConnectionAccessDao.php';
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/model/factory/ConnectionFactory.php';
	
	error_reporting (E_ALL ^ E_NOTICE);
	
	$debug = $_SESSION['debug'];

  	class MySqlPurchaseOrderAccessDao implements IPurchaseOrderAccessDao {
  		/**
		 * Constructor of the Purchase Order dao
		 */
	 	public function __construct () {}
		
		/**
		 * Creates a Purchase Order
		 */
     	public function createPurchaseOrder($purchaseOrder) {
			$pkNumber = $purchaseOrder -> getPkNumber();
			$pkControlNumber = $purchaseOrder -> getPkControlNumber();
			$date = $purchaseOrder -> getDate();
			$tax = $purchaseOrder -> getTax();
			$readStatus = $purchaseOrder -> getReadStatus();
			$idClient = $purchaseOrder -> getIdClient();
			$ciRif = $purchaseOrder -> getCiRif();
			
			$connection = ConnectionFactory :: getMySqlConnectionAccessDao();
			$conn = $connection -> openConnection();
			$GLOBALS['debug'] -> log($purchaseOrder,"LLEGO al DAO -- Purchase Order");
			
			if (strcmp($ciRif, 'ci') == 0)
			{

					$GLOBALS['debug'] -> log($purchaseOrder,"LLEGO al DAO cliente natural -- Purchase Order");
					$query = "INSERT INTO PURCHASE_ORDER (pk_number, pk_control_number, date, tax,read_status,
					fk_id_number_natural_customer) VALUES ($pkNumber, $pkControlNumber, '$date', 
					$tax,'$readStatus','$idClient')";
			}
			else
			{
				$GLOBALS['debug'] -> log($purchaseOrder,"LLEGO al DAO cliente juridico-- Purchase Order");
			
				$query = "INSERT INTO PURCHASE_ORDER (pk_number, pk_control_number, date, tax, read_status,
					fk_rif_legal_client) VALUES ($pkNumber, $pkControlNumber, '$date', 
					$tax,'$readStatus', '$idClient')";
					
			}
			$sentence = mysql_query($query, $conn);
			
			if ($sentence)
				return true;
			
			return false;
	 	}

  }


?>